<%@page import="bean.MemberVo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="bean.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>list</title>

<link rel="stylesheet" href="./css/member.css">
<script src="./js/member.js"></script>

</head>
<body>
<jsp:useBean id="vo" class="bean.MemberVo"></jsp:useBean>
<jsp:setProperty property="*" name="vo"/>
<h1>LIST</h1>
<div id="list_title">
		<div class="list_mid">아이디</div>
		<div class="list_irum">이름</div>
		<div class="list_nicname">닉네임</div>
		<div class="list_photo">사진</div>
</div>
<%
	MemberDTO dto = new MemberDTO();

ArrayList<MemberVo> ar=dto.select();

int limit = (int)Math.ceil(ar.size()*1.0/10);      //(arr.size()/10)+1;   // 마지막 페이지
int startpage=0;				//시작 페이지
int endpage =9;                 //한페이지의 마지막 행
int first=1;					//한페이지의 시작 행
int listfirst=1;				//리스트의 시작
int listend = 5;				//리스트의 마지막
int nowpage=1;					//현재 페이지
int getpage = 1;				//파라미터로 넘어오는 페이지 값

if(ar.size()<10){				//마지막 페이지의 행 조건문
	endpage = ar.size()-1; 	
}


if(request.getParameter("page")!=null){
	getpage = Integer.parseInt(request.getParameter("page"));
	if(getpage==limit){
	startpage =  (getpage*10)-10;
	endpage = ar.size()-1;
	nowpage = getpage;
	}else{
	startpage =  (getpage*10)-10;
	endpage =startpage+9;	
	nowpage = getpage;
	}
	
}
int uppage=nowpage+1;    // 페이지 이동  +
int downpage=nowpage-1;  // 페이지 이동  -
if(downpage<=1){downpage=1;}
if(uppage>=limit){uppage=limit;}
if(nowpage>5){
	switch(nowpage%5){
		case 0: listfirst=(nowpage-4); break;
		case 1:	listfirst=nowpage; break;
		case 2:	listfirst=(nowpage-1); break;
		case 3:	listfirst=(nowpage-2); break;
		case 4:	listfirst=(nowpage-3); break;
	}
}else if(nowpage<=5){
	listfirst = 1;
}

listend=listfirst+4;
if(listend>=limit){listend=limit;}

for(int a=startpage;a<=endpage;a++){
	MemberVo v = ar.get(a);
	out.print("<a href='#' onclick='goView(\""+v.getMid()+"\")'>"
	+"<div class='list_item'>"
	+"<div class='list_mid'>" + v.getMid() +"</div>"
	+"<div class='list_irum'>"+v.getIrum() +"</div>"
	+"<div class='list_nicname'>"+v.getNickname() +"</div>"
	+"<div class='list_photo'>"+v.getPhoto() +"</div>"
	+"</div></a>");
}
%>
<br>
	<%=nowpage %>
	Page
<br>
<center></center>
	<a href='#' onclick='goPage(<%=first%>)'>[처음으로]</a> &nbsp;&nbsp;
	<a href='#' onclick='goPage(<%=downpage%>)'>◀</a>
<% 
			for(int v=listfirst;v<=listend;v++){
			out.print("<a href='#' onclick='goPage("+v+")'>" +v+ "</a> ");}
		
%>
<a href='#' onclick='goPage(<%=uppage%>)'>▶</a> &nbsp;&nbsp;
	
	<a href='#' onclick='goPage(<%=limit%>)'>[마지막으로]</a></center>
		<br>
<br><br>
<input type="button" value="회원입력" id="btninput">

<script>listinit();</script>
</body>
</html>